﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbObjectContextCollection : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbObjectContextCollection(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbObjectContextCollection_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbObjectContextCollection obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbObjectContextCollection()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbObjectContextCollection(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdDbObjectContextCollection cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbObjectContextCollection_cast(OdRxObject.getCPtr(pObj));
			OdDbObjectContextCollection result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbObjectContextCollection)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbObjectContextCollection)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbObjectContextCollection)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbObjectContextCollection_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbObjectContextCollection_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbObjectContextCollection_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbObjectContextCollection createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbObjectContextCollection_createObject();
			OdDbObjectContextCollection result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbObjectContextCollection)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbObjectContextCollection)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbObjectContextCollection)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual string name()
		{
			string result = TD_DbPINVOKE.OdDbObjectContextCollection_name(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdDbObjectContext currentContext(OdDbObject pRequestingObject)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbObjectContextCollection_currentContext(this.swigCPtr, OdDbObject.getCPtr(pRequestingObject));
			OdDbObjectContext result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbObjectContext)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbObjectContext)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbObjectContext)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult setCurrentContext(OdDbObjectContext pContext)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbObjectContextCollection_setCurrentContext(this.swigCPtr, OdDbObjectContext.getCPtr(pContext));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult addContext(OdDbObjectContext pContext)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbObjectContextCollection_addContext(this.swigCPtr, OdDbObjectContext.getCPtr(pContext));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult removeContext(string contextName)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbObjectContextCollection_removeContext(this.swigCPtr, contextName);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult lockContext(OdDbObjectContext pContext)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbObjectContextCollection_lockContext(this.swigCPtr, OdDbObjectContext.getCPtr(pContext));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult unlockContext()
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbObjectContextCollection_unlockContext(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool locked()
		{
			bool result = TD_DbPINVOKE.OdDbObjectContextCollection_locked(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdDbObjectContext getContext(string contextName)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbObjectContextCollection_getContext(this.swigCPtr, contextName);
			OdDbObjectContext result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbObjectContext)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbObjectContext)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbObjectContext)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool hasContext(string contextName)
		{
			bool result = TD_DbPINVOKE.OdDbObjectContextCollection_hasContext(this.swigCPtr, contextName);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdDbObjectContextCollectionIterator newIterator()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbObjectContextCollection_newIterator(this.swigCPtr);
			OdDbObjectContextCollectionIterator result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbObjectContextCollectionIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbObjectContextCollectionIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbObjectContextCollectionIterator)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;
	}
}
